package com.omronservice.utils;

import net.sf.json.JSONObject;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * Created by cool on 17/6/1.
 */
public class OmronConstant {
    public final static String LIST = "list";

    public final static String S1_STS = "S1_STS";
    public final static String S1_S_ID = "S1_S_ID";
    public final static String S1_S_STS = "S1_S_STS";


    public static class childBean{
        public String stack_index="";
        public String stack_status="";
        public String silicon_id="";
        public String silicon_status="";
        public String stack_in="";
        public String stack_out="";

        public String getStack_in() {
            return stack_in;
        }

        public void setStack_in(String stack_in) {
            this.stack_in = stack_in;
        }

        public String getStack_out() {
            return stack_out;
        }

        public void setStack_out(String stack_out) {
            this.stack_out = stack_out;
        }

        public String getStack_index() {
            return stack_index;
        }

        public void setStack_index(String stack_index) {
            this.stack_index = stack_index;
        }

        public String getStack_status() {
            return stack_status;
        }

        public void setStack_status(String stack_status) {
            this.stack_status = stack_status;
        }

        public String getSilicon_id() {
            return silicon_id;
        }

        public void setSilicon_id(String silicon_id) {
            this.silicon_id = silicon_id;
        }

        public String getSilicon_status() {
            return silicon_status;
        }

        public void setSilicon_status(String silicon_status) {
            this.silicon_status = silicon_status;
        }
    }

    public static JSONObject getJsonObject(JSONObject json) {
        JSONObject returnJson=new JSONObject();
        List<childBean> list=new ArrayList<childBean>();

        Iterator<?> it = json.keys();
        while (it.hasNext()) {
            String key = (String) it.next();
            switch (key){
                case OmronConstant.S1_STS:
                    OmronConstant.childBean childBean= new OmronConstant.childBean();
                    childBean.setStack_index("1");
                    childBean.setStack_status(json.getString(key));
                    childBean.setSilicon_id(json.getString(OmronConstant.S1_S_ID));
                    childBean.setSilicon_id(json.getString(OmronConstant.S1_S_STS));
                    list.add(childBean);
                    break;
                default:
                    returnJson.put(key,json.getString(key));

            }
        }
        returnJson.put(OmronConstant.LIST,list);
        return returnJson;
    }
}
